unit IdeInterface;

interface

uses
  ToolsAPI;

procedure register;

function InitWizard(const BorlandIDEServices: IBorlandIDEServices; RegisterProc: TWizardRegisterProc; var Terminate: TWizardTerminateProc) : Boolean; stdcall;

exports
  InitWizard name WizardEntryPoint;

implementation

uses
  IDEWizard, IDENotifier;

const
  InvalidIndex = -1;

var
  nWizardIndex: Integer = InvalidIndex;
  nIDENotifierIndex: Integer = InvalidIndex;

procedure FinalizeWizard;
begin
  if nWizardIndex <> InvalidIndex then begin
    (BorlandIDEServices as IOTAWizardServices).RemoveWizard(nWizardIndex);
    nWizardIndex := InvalidIndex;
  end;
  if nIDENotifierIndex <> InvalidIndex then begin
    (BorlandIDEServices as IOTAServices).RemoveNotifier(nIDENotifierIndex);
    nIDENotifierIndex := InvalidIndex;
  end;
end;

function InitialiseWizard: TIdeWizard;
begin
  ToolsAPI.BorlandIDEServices := BorlandIDEServices;

  Result := TIdeWizard.Create;
  nWizardIndex      := (BorlandIDEServices as IOTAWizardServices).AddWizard(Result);
  nIDENotifierIndex := (BorlandIDEServices as IOTAServices).AddNotifier(TIDENotifier.Create);
end;

function InitWizard(const BorlandIDEServices: IBorlandIDEServices; RegisterProc: TWizardRegisterProc; var Terminate: TWizardTerminateProc) : Boolean; stdcall;
begin
  Result := (BorlandIDEServices <> nil);
  if Result then
    RegisterProc(InitialiseWizard);
end;

procedure Register;
begin
  InitialiseWizard;
end;

initialization

finalization
  FinalizeWizard;

end.
